package com.tanhua.server.controller;

import com.tanhua.domain.vo.MomentVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.VideoVo;
import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 小视频控制层
 */
@RestController
@RequestMapping("/smallVideos")
public class VideoController {
    @Autowired
    private VideoService videoService;

    /**
     * 发布小视频
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity postSmallVideos(MultipartFile videoThumbnail,MultipartFile videoFile){
        videoService.postSmallVideos(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

    /**
     * 小视频列表查询
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity querySmallVideos(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize){
        PageResult<VideoVo> pageResult = videoService.querySmallVideos(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 关注用户
     */
    @RequestMapping(value = "/{uid}/userFocus",method = RequestMethod.POST)
    public ResponseEntity userFocus(@PathVariable("uid") long followUserId){
        videoService.userFocus(followUserId);
        return ResponseEntity.ok(null);
    }


    /**
     * 取消关注用户
     */
    @RequestMapping(value = "/{uid}/userUnFocus",method = RequestMethod.POST)
    public ResponseEntity userUnFocus(@PathVariable("uid") long followUserId){
        videoService.userUnFocus(followUserId);
        return ResponseEntity.ok(null);
    }

}
